﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using élénkPróbája.extentions;
using élénkPróbája.Test.dto;
using élénkPróbája.Test.extention;

namespace élénkPróbája.Test
{
    [TestClass]
    public class CreditCardValidatorTester
    {
        TestValidator validator;

        public CreditCardValidatorTester()
        {
            CultureScope.SetDefaultCulture();

            validator = new TestValidator {
                v => v.RuleFor(x => x.Owner.CreditCard).CreditCard()
            };
        }

        [TestMethod] 
        public void IsValidTests()
        {
            validator.Validate(new Company() { Owner = new Person() {CreditCard = null }}).IsValid.ShouldBeTrue(); // Optional values are always valid
            validator.Validate(new Company() { Owner = new Person() { CreditCard = "0000000000000000" }}).IsValid.ShouldBeTrue(); // Simplest valid value
            validator.Validate(new Company() { Owner = new Person() { CreditCard = "1234567890123452" }}).IsValid.ShouldBeTrue(); // Good checksum
            validator.Validate(new Company() { Owner = new Person() { CreditCard = "1234-5678-9012-3452" }}).IsValid.ShouldBeTrue(); // Good checksum, with dashes
            validator.Validate(new Company() { Owner = new Person() { CreditCard = "1234 5678 9012 3452" }}).IsValid.ShouldBeTrue(); // Good checksum, with spaces
            validator.Validate(new Company() { Owner = new Person() { CreditCard = "0000000000000001" }}).IsValid.ShouldBeFalse(); // Bad checksum
        }
        [TestMethod]
        public void When_validation_fails_the_default_error_should_be_set()
        {
            string creditcard = "foo";
            var result = validator.Validate(new Company() { Owner = new Person() { CreditCard = creditcard }});
            result.Errors.Single().ErrorMessage.ShouldEqual("'' is not a valid credit card number.");
        }

    }
}
